package com.xiyu.service.framework.postOffice.sync;

import com.xiyu.service.framework.postOffice.factory.PostOfficeFactory;
import com.xiyu.service.framework.postOffice.service.PostOfficeService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.concurrent.CompletableFuture;

@Component
public class SyncDownloadMailHeader {

    @Resource
    private PostOfficeFactory postOfficeFactory;


    @Async
    public CompletableFuture<Void> downloadMailHeaderTask(int begin, int end, Runnable onComplete, Long accountId, Long folderId) {
        PostOfficeService postOfficeService = postOfficeFactory.getInstance(accountId);
        postOfficeService.downloadMailHeaderTask(begin, end, onComplete, folderId);
        postOfficeService.close();

        // 等待所有链式任务完成
        return CompletableFuture.completedFuture(null);
    }

}
